package com.community.web.controller.building;

import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.core.page.TableDataInfo;
import com.community.domain.BuildingEntity;
import com.community.service.BuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/building")
public class BuildingController extends BaseController {
    @Autowired
    private BuildingService buildingService;
    @PreAuthorize("@ss.hasPermi('building:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(BuildingEntity building) {
        startPage();
        List<BuildingEntity> list=buildingService.selectBuildingList(building);
        return getDataTable(list);
    }
    @PreAuthorize("@ss.hasPermi('building:building:add')")
    @PostMapping("/addBuilding")
    public AjaxResult addBuilding(@RequestBody BuildingEntity building) {
        return toAjax(buildingService.addBuilding(building));
    }
    @PreAuthorize("@ss.hasPermi('building:building:edit')")
    @PutMapping("/updateBuilding")
    public AjaxResult updateBuilding(@Validated @RequestBody BuildingEntity building)
    {
        return toAjax(buildingService.updateBuilding(building));
    }
    @PreAuthorize("@ss.hasPermi('building:building:remove')")
    @DeleteMapping ("/{id}")
    public AjaxResult deleteById(@PathVariable int id) {
        return toAjax(buildingService.deleteById(id));
    }
}
